﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Demo_DrawGDI
{
    public partial class Frm_DrawGDI : Form
    {
        public Frm_DrawGDI()
        {
            InitializeComponent();
            snsPictureBox1.Color = Color.Lime;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //创建图像
            Bitmap bitmap = new Bitmap(1024, 800, PixelFormat.Format24bppRgb);
            //给图像涂上背景色
            Graphics gs = Graphics.FromImage(bitmap);
            gs.FillRectangle(new SolidBrush(Color.FromArgb(255, 8, 8, 10)), new Rectangle(0, 0, bitmap.Width, bitmap.Height));
            gs.Dispose();
            snsPictureBox1.Image = bitmap;
        }

        private void snsPictureBox1_Paint(object sender, PaintEventArgs e)
        {
            snsPictureBox1.ShowRect(new RectangleF(200, 100, 100, 100), true, 1);
            snsPictureBox1.ShowFillRect(new RectangleF(600, 100, 100, 100), true);
            snsPictureBox1.ShowLine(new PointF(200, 300), new PointF(300, 300), true, 1);
            snsPictureBox1.ShowPoint(new PointF(450, 300), 3);
            snsPictureBox1.ShowCross(new PointF(650, 300), 5, 1);

            snsPictureBox1.ShowCircle(new PointF(250, 400), 50, true, 1);
            snsPictureBox1.ShowFillCircle(new PointF(650, 400), 50, true);
            snsPictureBox1.ShowArc(new PointF(400, 400), 50, 10, 120, true, 1);
            snsPictureBox1.ShowFillArc(new PointF(500, 400), 50, 10, 120);

            List<System.Drawing.PointF> listPt = new List<System.Drawing.PointF>();
            listPt.Add(new System.Drawing.Point(150, 600));
            listPt.Add(new System.Drawing.Point(250, 500));
            listPt.Add(new System.Drawing.Point(350, 550));
            listPt.Add(new System.Drawing.Point(350, 650));
            listPt.Add(new System.Drawing.Point(250, 650));
            listPt.Add(new System.Drawing.Point(150, 600));
            snsPictureBox1.ShowPolygon(listPt, false, 1);

            List<System.Drawing.PointF> listPt2 = new List<System.Drawing.PointF>();
            listPt2.Add(new System.Drawing.Point(150 + 400, 600));
            listPt2.Add(new System.Drawing.Point(250 + 400, 500));
            listPt2.Add(new System.Drawing.Point(350 + 400, 550));
            listPt2.Add(new System.Drawing.Point(350 + 400, 650));
            listPt2.Add(new System.Drawing.Point(250 + 400, 650));
            listPt2.Add(new System.Drawing.Point(150 + 400, 600));
            snsPictureBox1.ShowFillPolygon(listPt2, true);
        }
    }
}
